package com.util;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Utiles {
	
public List<String> leerTodo(String ruta) {
		
		List<String> todoTexto = null;
		try {
			
			
			todoTexto = Files.readAllLines(Paths.get(ruta), Charset.defaultCharset());
					
			
			
		} catch (IOException e) {
			System.err.println("Error: "+e.getLocalizedMessage());
			e.printStackTrace();
		}
		
		
			
		return todoTexto;
	}


public Object[] listaAArreglo(List<String> toChange) {
	
	/*String[] temp = new String[toChange.size()];
	temp = (String[]) toChange.toArray(temp);
	
	*/
	
	List<String> tempArr = new ArrayList<String>();
	String temp = convertirACadenaSencilla(toChange);
	
	StringTokenizer st = new StringTokenizer(temp);
	while(st.hasMoreTokens())
	{
		tempArr.add(st.nextToken());
	}
	
	//objResult[] = new ArrayList<Object>(tempArr);
	
	return tempArr.toArray();
	
}

public String convertirACadenaSencilla(List<String> aConvertir){

	String temp = aConvertir.get(0);
	return temp.substring(3, temp.length()).replace("\"", "").replace(",","\n").replace(" ", "");
	
}


public void formatearParaGuardar(String aFormatear,String ruta) {
	
	
	String temp = new String();
	StringTokenizer st = new StringTokenizer(aFormatear);
	while(st.hasMoreTokens())
	{
		temp+="\""+st.nextElement()+"\", ";
	}
	
	temp = "\"\", "+temp.substring(0,temp.length()-2);
	System.out.println(); 
	
	
	try {
		Files.write(Paths.get(ruta), temp.getBytes());
	} catch (IOException e) {

		System.err.println("Error: "+e.getLocalizedMessage());
		e.printStackTrace();
	}

	
}



public void formatearParaGuardar(String aFormatear,String ruta, String nada) {
	
	
	String temp = new String();
	StringTokenizer st = new StringTokenizer(aFormatear);
	while(st.hasMoreTokens())
	{
		temp+="\""+st.nextElement()+"\", ";
	}
	
	temp = "\"\", "+temp.substring(0,temp.length()-2);
	System.out.println(); 
	
	
	try {
		Files.write(Paths.get(ruta), temp.getBytes());
	} catch (IOException e) {

		System.err.println("Error: "+e.getLocalizedMessage());
		e.printStackTrace();
	}

	
}


}